﻿/*
* Sale_order_article.cs
*
* 功 能： N/A
* 类 名： Sale_order_article
*
* Ver    变更日期             负责人     变更内容
* ───────────────────────────────────
* V1.0  2016-03-08 08:53:11    黄润伟    
*
* Copyright © 2015 www.xhdcrm.com All rights reserved.
*┌──────────────────────────────────┐
*│　版权所有：小黄豆                      　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using XHD.DBUtility;//Please add references
namespace XHD.DAL
{
    /// <summary>
	/// 数据访问类:Sale_order_article
	/// </summary>
	public partial class Sale_order_article
    {
        public Sale_order_article()
        { }

        #region  BasicMethod
        
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(XHD.Model.Sale_order_article model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Sale_order_article(");
            strSql.Append("id,xhs_code,xhs_articlelink,xhs_articletitle,xhs_articlepraise,xhs_articlecomment,xhs_articlecollect,xhs_publishtime,xhs_nickname,xhs_notes,xhs_fun,xhs_praise,xhs_collecttime,create_id,create_time,xhs_article_code,xhs_remark)");
            strSql.Append(" values (");
            strSql.Append("@id,@xhs_code,@xhs_articlelink,@xhs_articletitle,@xhs_articlepraise,@xhs_articlecomment,@xhs_articlecollect,@xhs_publishtime,@xhs_nickname,@xhs_notes,@xhs_fun,@xhs_praise,@xhs_collecttime,@create_id,@create_time,@xhs_article_code,@xhs_remark)");
            SqlParameter[] parameters = {
                new SqlParameter( "@id", SqlDbType.VarChar,500),
                new SqlParameter( "@xhs_code", SqlDbType.VarChar,500),
                new SqlParameter( "@xhs_articlelink", SqlDbType.VarChar,500),
                new SqlParameter( "@xhs_articletitle", SqlDbType.VarChar,500),
                new SqlParameter( "@xhs_articlepraise", SqlDbType.Int,4),
                new SqlParameter( "@xhs_articlecomment", SqlDbType.Int,4),
                new SqlParameter( "@xhs_articlecollect", SqlDbType.Int,4),
                new SqlParameter( "@xhs_publishtime", SqlDbType.VarChar,500),
                new SqlParameter( "@xhs_nickname", SqlDbType.VarChar,500),
                new SqlParameter( "@xhs_notes", SqlDbType.Int,4),
                new SqlParameter( "@xhs_fun", SqlDbType.Int,4),
                new SqlParameter( "@xhs_praise", SqlDbType.Int,4),
                new SqlParameter( "@xhs_collecttime", SqlDbType.DateTime),
                new SqlParameter( "@create_id", SqlDbType.VarChar,500),
                new SqlParameter( "@create_time", SqlDbType.DateTime),
                new SqlParameter( "@xhs_article_code", SqlDbType.VarChar,500),
                new SqlParameter( "@xhs_remark", SqlDbType.VarChar,500)
            };

            parameters[0].Value = model.id;
            parameters[1].Value = model.xhs_code;
            parameters[2].Value = model.xhs_articlelink;
            parameters[3].Value = model.xhs_articletitle;
            parameters[4].Value = model.xhs_articlepraise;
            parameters[5].Value = model.xhs_articlecomment;
            parameters[6].Value = model.xhs_articlecollect;
            parameters[7].Value = model.xhs_publishtime;
            parameters[8].Value = model.xhs_nickname;
            parameters[9].Value = model.xhs_notes;
            parameters[10].Value = model.xhs_fun;
            parameters[11].Value = model.xhs_praise;
            parameters[12].Value = model.xhs_collecttime;
            parameters[13].Value = model.create_id;
            parameters[14].Value = model.create_time;
            parameters[15].Value = model.xhs_article_code;
            parameters[16].Value = model.xhs_remark;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            return rows > 0 ? true : false;
        }

        /// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(XHD.Model.Sale_order_article model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Sale_order_article set ");
            strSql.Append("xhs_code = @xhs_code,");
            strSql.Append("xhs_articlelink = @xhs_articlelink,");
            strSql.Append("xhs_articletitle = @xhs_articletitle,");
            strSql.Append("xhs_articlepraise = @xhs_articlepraise,");
            strSql.Append("xhs_articlecomment = @xhs_articlecomment,");
            strSql.Append("xhs_articlecollect = @xhs_articlecollect,");
            strSql.Append("xhs_publishtime = @xhs_publishtime,");
            strSql.Append("xhs_nickname = @xhs_nickname,");
            strSql.Append("xhs_notes = @xhs_notes,");
            strSql.Append("xhs_fun = @xhs_fun,");
            strSql.Append("xhs_praise = @xhs_praise,");
            strSql.Append("xhs_collecttime = @xhs_collecttime,");
            strSql.Append("xhs_article_code = @xhs_article_code,");
            strSql.Append("xhs_remark = @xhs_remark");

            strSql.Append(" where id=@id ");

            SqlParameter[] parameters = {
                new SqlParameter( "@xhs_code", SqlDbType.VarChar,500),
                new SqlParameter( "@xhs_articlelink", SqlDbType.VarChar,500),
                new SqlParameter( "@xhs_articletitle", SqlDbType.VarChar,500),
                new SqlParameter( "@xhs_articlepraise", SqlDbType.Int,4),
                new SqlParameter( "@xhs_articlecomment", SqlDbType.Int,4),
                new SqlParameter( "@xhs_articlecollect", SqlDbType.Int,4),
                new SqlParameter( "@xhs_publishtime", SqlDbType.VarChar,500),
                new SqlParameter( "@xhs_nickname", SqlDbType.VarChar,500),
                new SqlParameter( "@xhs_notes", SqlDbType.Int,4),
                new SqlParameter( "@xhs_fun", SqlDbType.Int,4),
                new SqlParameter( "@xhs_praise", SqlDbType.Int,4),
                new SqlParameter( "@xhs_collecttime", SqlDbType.DateTime),
                new SqlParameter( "@xhs_article_code", SqlDbType.VarChar,500),
                new SqlParameter( "@xhs_remark", SqlDbType.VarChar,500),
                new SqlParameter( "@id", SqlDbType.VarChar,500)
            };

            parameters[0].Value = model.xhs_code;
            parameters[1].Value = model.xhs_articlelink;
            parameters[2].Value = model.xhs_articletitle;
            parameters[3].Value = model.xhs_articlepraise;
            parameters[4].Value = model.xhs_articlecomment;
            parameters[5].Value = model.xhs_articlecollect;
            parameters[6].Value = model.xhs_publishtime;
            parameters[7].Value = model.xhs_nickname;
            parameters[8].Value = model.xhs_notes;
            parameters[9].Value = model.xhs_fun;
            parameters[10].Value = model.xhs_praise;
            parameters[11].Value = model.xhs_collecttime;
            parameters[12].Value = model.xhs_article_code;
            parameters[13].Value = model.xhs_remark;

            parameters[14].Value = model.id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            return rows > 0 ? true : false;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string whereStr)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Sale_order_article ");
            strSql.Append(" where "+whereStr);
           
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            return rows > 0 ? true : false;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere, bool isAll = false )
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT  ");
            strSql.Append("Sale_order_article.[id] ");
            strSql.Append(",Sale_order_article.[xhs_code] ");
            strSql.Append(",Sale_order_article.[xhs_articlelink] ");
            strSql.Append(",Sale_order_article.[xhs_articletitle] ");
            strSql.Append(",Sale_order_article.[xhs_articlepraise] ");
            strSql.Append(",Sale_order_article.[xhs_articlecomment] ");
            strSql.Append(",Sale_order_article.[xhs_articlecollect] ");
            strSql.Append(",Sale_order_article.[xhs_publishtime] ");
            strSql.Append(",Sale_order_article.[xhs_nickname] ");
            strSql.Append(",Sale_order_article.[xhs_notes] ");
            strSql.Append(",Sale_order_article.[xhs_fun] ");
            strSql.Append(",Sale_order_article.[xhs_praise] ");
            strSql.Append(",Sale_order_article.[xhs_collecttime] ");
            strSql.Append(",Sale_order_article.[create_id] ");
            strSql.Append(",Sale_order_article.[create_time] ");
            strSql.Append(",Sale_order_article.[xhs_article_code] ");
            strSql.Append(",Sale_order_article.[xhs_remark] ");

            strSql.Append(" FROM [dbo].[Sale_order_article] ");

            if (!isAll) strSql.Append(" INNER JOIN Sale_order_sheet ON [Sale_order_article].xhs_article_code =Sale_order_sheet.xhs_article_code INNER JOIN CRM_Customer on CRM_Customer.xhs_code=Sale_order_sheet.xhs_code");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder, bool isAll = false)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append("Sale_order_article.[id] ");
            strSql.Append(",Sale_order_article.[xhs_code] ");
            strSql.Append(",Sale_order_article.[xhs_articlelink] ");
            strSql.Append(",Sale_order_article.[xhs_articletitle] ");
            strSql.Append(",Sale_order_article.[xhs_articlepraise] ");
            strSql.Append(",Sale_order_article.[xhs_articlecomment] ");
            strSql.Append(",Sale_order_article.[xhs_articlecollect] ");
            strSql.Append(",Sale_order_article.[xhs_publishtime] ");
            strSql.Append(",Sale_order_article.[xhs_nickname] ");
            strSql.Append(",Sale_order_article.[xhs_notes] ");
            strSql.Append(",Sale_order_article.[xhs_fun] ");
            strSql.Append(",Sale_order_article.[xhs_praise] ");
            strSql.Append(",ISNULL(CONVERT(NVARCHAR(10),Sale_order_article.[xhs_collecttime],120),'') AS xhs_collecttime  ");
            strSql.Append(",Sale_order_article.[create_id] ");
            strSql.Append(",Sale_order_article.[create_time] ");
            strSql.Append(",Sale_order_article.[xhs_article_code] ");
            strSql.Append(",Sale_order_article.[xhs_remark] ");

            strSql.Append(" FROM [dbo].[Sale_order_article] ");

            if (!isAll) strSql.Append("  INNER JOIN CRM_Customer ON CRM_Customer.xhs_code =Sale_order_sheet.xhs_code INNER JOIN Sale_order_article.xhs_article_code=Sale_order_sheet.xhs_article_code ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }
        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

